package com.resource.collect.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.util.HashMap;

/**
 * Created by Feng on 2019/12/25 14:15
 * CurrentProject's name is spring-boot-learning
 *
 * @author Feng
 */
@Configuration
public class DruidConfig {

//    @ConfigurationProperties(prefix = "spring.datasource")
//    @Bean
//    public DataSource druid() {
//        DruidDataSource druidDataSource = new DruidDataSource();
//        return druidDataSource;
//    }
//
//
//    @Bean
//    public JdbcTemplate jdbcTemplate(@Autowired DataSource dataSource) {
//        return new JdbcTemplate(dataSource);
//    }

    /**
     * 没有配置打不开管理页面
     *
     * @return
     */
//    @Bean
//    public ServletRegistrationBean statViewServlet() {
//        StatViewServlet statViewServlet = new StatViewServlet();
//        //向容器中注入 StatViewServlet，并将其路径映射设置为 /druid/*
//        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(statViewServlet, "/druid/*");
//        //配置监控页面访问的账号和密码（选配）
//        servletRegistrationBean.addInitParameter("loginUsername", "admin");
//        servletRegistrationBean.addInitParameter("loginPassword", "123456");
//        return servletRegistrationBean;
//    }

    /**
     * 没有配置监控没有数据
     *
     * @return
     */
//    @Bean
//    public FilterRegistrationBean webStatFilter() {
//        FilterRegistrationBean bean = new FilterRegistrationBean();
//        bean.setFilter(new WebStatFilter());
//
//        HashMap<String, String> initParameters = new HashMap<>();
//        initParameters.put("exclusions", "*.js,*.css,/druid/*");
//
//        bean.setInitParameters(initParameters);
//        return bean;
//    }


}
